<?php

class OnlineTask extends sfBaseTask
{
  protected function configure()
  {
    // // add your own arguments here
    // $this->addArguments(array(
    //   new sfCommandArgument('my_arg', sfCommandArgument::REQUIRED, 'My argument'),
    // ));

    $this->addOptions(array(
      new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name','frontend'),
      new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
      new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'propel'),
      // add your own options here
    ));

    $this->namespace        = 'frontend';
    $this->name             = 'online';
    $this->briefDescription = '';
    $this->detailedDescription = <<<EOF
The [ba:recount|INFO] task does things.
Call it with:

  [php symfony ba:recount|INFO]
EOF;
  }

  protected function execute($arguments = array(), $options = array())
  {
    // initialize the database connection
    $databaseManager = new sfDatabaseManager($this->configuration);
    $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
    $this->context = sfContext::createInstance($this->configuration);

    $c = new Criteria();
    $c->add(sfGuardUserPeer::IS_ONLINE,true);
    //$c->add(sfGuardUserPeer::PARTNER_ID,606,Criteria::NOT_EQUAL);
    $us = sfGuardUserPeer::doSelect($c);

    $now = time();

        foreach($us as $u)
        {
            $re = $now - $u->getTime();
            if($re>420)
                {
                    $u->setIsOnline(false);
                    $u->save();
                }
            echo $u.'-'.$re.'|';
        }

   
   
   
   
   
  }
  
	
  
}
